<template>
  <el-dialog
    class="eldialog el-dialog-m0"
    :visible.sync="visible"
    :title="title"
    :close-on-click-modal="false"
    append-to-body
    top="2vh"
    width="100%"
    :close-on-press-escape="false"
    element-loading-text="数据加载中"
    v-loading="loading"
  >
    <el-form :inline="true" :model="msgData" :rules="rules" ref="msgData" class="demo-form-inline">
      <el-row>
        <el-col :span="24" align="center">
          <el-form-item prop="dw">
            <el-input :disabled="flag" maxlength="30" size="small" placeholder="请输入单位名称" v-model="msgData.dw"></el-input>
          </el-form-item>
          <span style="font-size: 28px;line-height: 32px;font-weight: 900;height: 50px;">2023年度年轻干部年度推进情况统计表</span>
          <el-button style="margin-right: 30px;margin-top: 10px;float: right" type="primary" plain @click="downZip"
          >&nbsp;导出<i class="el-icon-upload el-icon--right"></i>
          </el-button>

          <el-button v-if="btType === '2'" style="margin-right: 10px;margin-top: 10px;float: right" type="primary"
                     icon="el-icon-edit" plain
                     @click="auditTable()" :disabled="shztMid === '1' || shztGHB === '1'">&nbsp;审核
          </el-button>
          <el-button v-if="btType === '2' && (shztMid === '1'||shztGHB === '1')"
                     style="margin-right: 10px;margin-top: 10px;float: right" type="primary" icon="el-icon-edit" plain
                     @click="flag = false;shztMid = '0';shztGHB = '0'">&nbsp;修改
          </el-button>
          <el-button v-if="role == '系统管理员'" style="margin-right: 10px;margin-top: 10px;float: right" type="primary"
                     icon="el-icon-edit" plain
                     @click="save('msgData')">&nbsp;保存
          </el-button>
          <el-button v-else style="margin-right: 10px;margin-top: 10px;float: right" type="primary" icon="el-icon-edit"
                     plain
                     @click="save('msgData')" :disabled="flag">&nbsp;保存
          </el-button>

        </el-col>
      </el-row>
      <!--<el-row>
        <el-button  style="margin-right: 30px;margin-top: 10px;float: right" type="primary" plain @click="detailList( '1', 'csny','中层副职全部人员')">全部正{{num1}}</el-button>
        <el-button  style="margin-right: 30px;margin-top: 10px;float: right" type="primary" plain @click="detailList( '2', 'csny','中层副职全部人员')">全部副{{num2}}</el-button>
        <el-button   style="margin-right: 30px;margin-top: 10px;float: right" type="primary" plain @click="detailList2( '1', 'csny','中层副职全部人员')">部分正{{num3}}</el-button>
        <el-button  style="margin-right: 30px;margin-top: 10px;float: right" type="primary" plain @click="detailList2( '2', 'csny','中层副职全部人员')">部分副{{num4}}</el-button>
      </el-row>-->
      <el-row>
        <el-form-item lable="填表人：" prop="tbr">
          <el-input :disabled="flag" maxlength="15" size="small" placeholder="请输入填表人姓名"
                    v-model="msgData.tbr">
          </el-input>
        </el-form-item>
        <el-form-item lable="联系方式：" prop="lxfs">
          <el-input :disabled="flag" size="small" placeholder="请输入联系方式"
                    oninput="if(value.length>15)value=value.slice(0,15)"
                    v-model="msgData.lxfs">
          </el-input>
        </el-form-item>
      </el-row>
    </el-form>
    <el-row>
      <vxe-table style="width: 100%"
                border
                :data="tjqktjData">
        <vxe-column
          title="人员构成"
          align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.rygc == '1'">全部人员</span>
            <span v-if="scope.row.rygc != '1'">机关+参公</span>
          </template>
        </vxe-column>
        <vxe-colgroup
          title="中层正职（正处级领导职务）"
          align="center">
          <vxe-column
            title="批复职数"
            align="center">
            <template slot-scope="scope">
              <el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzPfzs = $event.target.value"
                        v-model="scope.row.zczzPfzs">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            title="实配数"
            align="center">
            <template slot-scope="scope">
              <el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzSps = $event.target.value"
                        v-model="scope.row.zczzSps">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>2022年底</div>
                <div>41岁以下</div>
                <div>干部数</div>
              </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzPb41nsl = $event.target.value"
                        v-model="scope.row.zczzPb41nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
              <div>2022年底</div>
              <div>41岁以下</div>
              <div>干部占比</div>
            </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzPb41nslzb = $event.target.value"
                        v-model="scope.row.zczzPb41nslzb">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>2023年内</div>
                <div>计划补充41岁</div>
                <div>以下干部人数</div>
              </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzBc41nsl = $event.target.value"
                        v-model="scope.row.zczzBc41nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>2023年底</div>
                <div>41岁以下干部</div>
                <div>人数计划达到</div>
              </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzDd41nsl = $event.target.value"
                        v-model="scope.row.zczzDd41nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>目前配备</div>
                <div>41岁以下</div>
                <div>干部数</div>
              </template>
            <template slot-scope="scope">
              <el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzMq41nsl = $event.target.value"
                        v-model="scope.row.zczzMq41nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
              <div>全省干部</div>
              <div>数据中心</div>
              <div>筛选41岁以</div>
              <div>下干部人数</div>
            </template>
            <template slot-scope="scope">
              <!--<el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zczzSjzx41 = $event.target.value"
                        v-model="scope.row.zczzSjzx41">
              </el-input>-->
              <el-button v-if="scope.row.rygc == '1'" type="text"  :disabled="scope.row.zczzSjzx41==0"
                         @click="detailList( '1', 'csny','中层正职全部人员')"
                         size="small">{{scope.row.zczzSjzx41}}</el-button>
              <el-button v-if="scope.row.rygc != '1'" type="text"  :disabled="scope.row.zczzSjzx41==0"
                         @click="detailList2( '1', 'csny','中层正职机关＋参公')"
                         size="small">{{scope.row.zczzSjzx41}}</el-button>
            </template>
          </vxe-column>
        </vxe-colgroup>
        <vxe-colgroup
          title="中层副职（副处级领导职务）"
          align="center">
          <vxe-column
            title="批复职数"
            align="center">
            <template slot-scope="scope">
              <el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzPfzs = $event.target.value"
                        v-model="scope.row.zcfzPfzs">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            title="实配数"
            align="center">
            <template slot-scope="scope">
              <el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzSps = $event.target.value"
                        v-model="scope.row.zcfzSps">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>2022年底</div>
                <div>36岁以下</div>
                <div>干部人数</div>
              </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzPb36nsl = $event.target.value"
                        v-model="scope.row.zcfzPb36nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
              <div>2022年底</div>
              <div>36岁以下</div>
              <div>干部占比</div>
            </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzPb36nslzb = $event.target.value"
                        v-model="scope.row.zcfzPb36nslzb">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>2023年内</div>
                <div>计划补充36岁</div>
                <div>以下干部人数</div>
              </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzBc36nsl = $event.target.value"
                        v-model="scope.row.zcfzBc36nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>2023年底</div>
                <div>36岁以</div>
                <div>下干部</div>
              </template>
            <template slot-scope="scope">
              <el-input disabled onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzDd36nsl = $event.target.value"
                        v-model="scope.row.zcfzDd36nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
                <div>目前配备</div>
                <div>36岁以下</div>
                <div>干部人数</div>
                <div>计划达到</div>
              </template>
            <template slot-scope="scope">
              <el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzMq36nsl = $event.target.value"
                        v-model="scope.row.zcfzMq36nsl">
              </el-input>
            </template>
          </vxe-column>
          <vxe-column
            align="center">
            <template slot="header">      
              <div>全省干部</div>
              <div>数据中心</div>
              <div>筛选36岁以</div>
              <div>下干部人数</div>
            </template>
            <template slot-scope="scope">
             <!-- <el-input :disabled="flag" onkeyup="value=value.replace(/^\D*(\d*).*/g, '$1')"  @blur="scope.row.zcfzSjzx36 = $event.target.value"
                        v-model="scope.row.zcfzSjzx36">
              </el-input>-->
              <el-button v-if="scope.row.rygc == '1'" type="text"  :disabled="scope.row.zcfzSjzx36==0"
                         @click="detailList( '2', 'csny','中层副职全部人员')"
                         size="small">{{scope.row.zcfzSjzx36}}</el-button>
              <el-button v-if="scope.row.rygc != '1'" type="text"   :disabled="scope.row.zcfzSjzx36==0"
                         @click="detailList2( '2', 'csny','中层副职机关＋参公')"
                         size="small">{{scope.row.zcfzSjzx36}}</el-button>
            </template>
          </vxe-column>
        </vxe-colgroup>
      </vxe-table>
    </el-row>
    <div>
      <detail-add v-if="showTypeList" ref="dialogSumCardreList"  />
    </div>
  </el-dialog>

</template>

<script>

  /*方法引用*/
  import {getList2023, save2023,downLsqk2023,auditTable} from '@/api/young/evaluation/infoFilling/infoFilling.js'
  import detailAlert from './detailAlert'
  import store from '@/store'
    import { getSzWarningTwoTable } from '@/api/young/echarts/cadre/cadreNew'
  // import { statisticsTwoList,statisticsTwoTwoList } from '@/api/young/echarts/cadre/cadreNew'
  export default {
    name: "tjqktjTable2023-sz",
    components: {
        'detail-add': detailAlert,
    },
    data() {
      return {
        dataForm: null,
        title: '推进情况统计表',
        visible: false,
        pdfUrl: '',
        heightY: window.innerHeight - 90 + 'px',
        heightZ: window.innerHeight - 360 + 'px',
        widthY: window.innerWidth / 2 - 50 + 'px',
        showTypeList: false,
        loading: false,
        flag:false,
        btType:'',
        role:'',
        shztMid:'',
        shztGHB:'',
        taskId: '',
        tjqktjData: [],
        msgData: {
          "id": "",
          "dw": "",
          "tbr": "",
          "lxfs": "",
          "taskId": "",
          "sjd": "mid"
        },
        rules: {
          tbr: [
            {required: true, message: '请输入填表人姓名', trigger: 'blur'}
          ],
          lxfs: [
            {required: true, message: '请输入联系方式', trigger: 'blur'}
          ],
          dw: [
            {required: true, message: '请输入单位名称', trigger: 'blur'}
          ],
        },
        reg : /^([1-9][0-9]*|0)(\.[0-9]*[1-9])?$/,
        num1:0,
        num2:0,
        num3:0,
        num4:0,
        task:{},
        orgId:"",
      }
    },
    mounted(){

    },
    methods: {
      async initShow(task,role,shztGHB,type) {
        this.task =task;

        this.btType = type;
        this.taskId = task.id;
        this.role = role;
        this.shztGHB = shztGHB;
        this.visible = true;
        this.msgData = {};
        this.tjqktjData = [];
        const params = {
          'taskId': task.id,
          'type': '4'
        };
        this.loading = true;
        getList2023(params).then((data) => {
          if (data.type) {
            if (data.resultdata.bt) {
              this.msgData = data.resultdata.bt
              this.shztMid = data.resultdata.bt.shztMid
            }
            if (data.resultdata.list) {
              this.tjqktjData = data.resultdata.list
              this.getSjzx(this.tjqktjData)
            }
            this.loading = false;
          } else {
            this.$message.error(data.message)
          }
          if (this.shztGHB == '1' || this.shztMid == '1'){

            this.flag = true;
          }else {

            var jgid= JSON.parse(sessionStorage.getItem(`userInfo`)).organizeId
            if (jgid !== task.dwBianma) {

              if (role == '系统管理员'||role.indexOf('干部一处')>-1||role.indexOf('干部二处')>-1||
                role.indexOf('干部三处')>-1||role.indexOf('干部四处')>-1||role.indexOf('干部五处')>-1) {

                this.flag = true;
              }else {

                this.flag = false;
              }
            }else {

              this.flag = false;
            }
          }
        })
      },

      //保存
      save(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$confirm('是否保存?', '操作提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.msgData.taskId = this.taskId;
              this.msgData.sjd = 'mid'
              this.tjqktjData.forEach((item) => {
                item.taskId = this.taskId;
              });
              const params = {
                'bt': this.msgData,
                'data': this.tjqktjData,
                'type': '4'
              };

              this.loading = true;
              save2023(params).then((data) => {

                if (data.result) {
                  this.loading = false;
                  this.$message.success('保存成功!')
                  this.visible = false;
                } else {
                  this.loading = false;
                  this.$message.error(data.message)
                }
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消保存'
              });
            });
          }
        });
      },

      //审核
      auditTable(){
        this.$confirm('是否审核通过?', '操作提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.msgData.taskId = this.taskId;
          this.msgData.sjd = 'begin'
           const params = {
            'id': this.msgData.id,
            'task': this.task,
            'type': '4'
          };
          this.loading = true;
          auditTable(params).then((data) => {
            if (data.result) {
              this.loading = false;
              this.$message.success('审核通过!')
              this.visible = false;
            } else {
              this.loading = false;
              this.$message.error(data.message)
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消审核!'
          });
        });
      },
        //下载
        downZip(){
            const month= new Date().getMonth() + 1;
            const params = {
                taskId: this.taskId,
                type : 4,
                fileName:this.msgData.dw+"年中统计(" +
                    new Date().getFullYear() +"年"+month+ "月).zip"
            }
            this.$confirm('是否下载?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.pageLoading = true;
                downLsqk2023(params).then(result => {
                    this.pageLoading = false;
                    // this.$alert('成功')
                })
            })
        },
        detailList( type, LeaderType,personType) {
          var b0111 = this.orgId
                var b0101=JSON.parse(sessionStorage.getItem(`userInfo`)).organizeName
                var alertPar = b0101+"--"+personType
                // eslint-disable-next-line no-unused-vars,no-redeclare
                // eslint-disable-next-line no-redeclare
                var that = this
                that.loading = true
                that.paramesList = []
                var uintName = ''
                var par_sjzx = {   // 默认值
                  'userId': store.getters.user_id.toString(),
                  'token': store.getters.token.toString(),
                  'system': 'datacenter',
                  'orgNumber': b0111,
                }
                if(type == '1'){
                  par_sjzx['leaderCategory'] = '1'
                  if(LeaderType == 'csny'){// 中层正职41岁
                    par_sjzx['csny'] = '41'
                  }else if(LeaderType == 'gender'){// 中层正职女
                    par_sjzx['gender'] = '2'
                  }else if(LeaderType == 'nation'){// 中层正职少数民族
                    par_sjzx['nation'] = '01'
                  }else if(LeaderType == 'zzmm'){// 中层正职党外干部
                    par_sjzx['zzmm'] = '01'
                  }

                }else {  // 中层副职数
                  par_sjzx['leaderCategory'] = '2'
                  if(LeaderType == 'csny'){// 中层副职36岁
                    par_sjzx['csny'] = '36'
                  }else if(LeaderType == 'gender'){// 中层副职女
                    par_sjzx['gender'] = '2'
                  }else if(LeaderType == 'nation'){// 中层副职少数民族
                    par_sjzx['nation'] = '01'
                  }else if(LeaderType == 'zzmm'){// 中层副职党外干部
                    par_sjzx['zzmm'] = '01'
                  }
                }
                par_sjzx['showType'] = 'two'
                that.showTypeList = true
                that.$nextTick(() => {
                  that.$refs.dialogSumCardreList.init(par_sjzx, alertPar)
                })
                that.loading = false
        },
        detailList2( type, LeaderType, personType) {
                var b0111 = this.orgId
                var b0101=JSON.parse(sessionStorage.getItem(`userInfo`)).organizeName
                var alertPar = b0101+"--"+personType
                // eslint-disable-next-line no-unused-vars,no-redeclare
                // eslint-disable-next-line no-redeclare
                var that = this
                that.loading = true
                that.paramesList = []
                var uintName = ''
                var par_sjzx = {   // 默认值
                  'userId': store.getters.user_id.toString(),
                  'token': store.getters.token.toString(),
                  'system': 'datacenter',
                  'orgNumber': b0111,
                  'isWay': '1'
                }
                if(type == '1'){
                  par_sjzx['leaderCategory'] = '1'
                  if(LeaderType == 'csny'){// 中层正职41岁
                    par_sjzx['csny'] = '41'
                  }else if(LeaderType == 'gender'){// 中层正职女
                    par_sjzx['gender'] = '2'
                  }else if(LeaderType == 'nation'){// 中层正职少数民族
                    par_sjzx['nation'] = '01'
                  }else if(LeaderType == 'zzmm'){// 中层正职党外干部
                    par_sjzx['zzmm'] = '01'
                  }

                }else {  // 中层副职数
                  par_sjzx['leaderCategory'] = '2'
                  if(LeaderType == 'csny'){// 中层副职36岁
                    par_sjzx['csny'] = '36'
                  }else if(LeaderType == 'gender'){// 中层副职女
                    par_sjzx['gender'] = '2'
                  }else if(LeaderType == 'nation'){// 中层副职少数民族
                    par_sjzx['nation'] = '01'
                  }else if(LeaderType == 'zzmm'){// 中层副职党外干部
                    par_sjzx['zzmm'] = '01'
                  }
                }
                par_sjzx['showType'] = 'twoTwo'
                that.showTypeList = true
                that.$nextTick(() => {
                  that.$refs.dialogSumCardreList.init(par_sjzx, alertPar)
                })
                that.loading = false
        },
        async getSjzx(tableData){
            tableData.forEach(item =>{
                    item.zczzSjzx41 =0
                    item.zcfzSjzx36 =0
            })
            const params_sjzx = {
                'userId': store.getters.user_id.toString(),
                'token': store.getters.token.toString(),
                'system': 'datacenter',
                'jg_id': this.task.dwBianma
            }
            const params_jgcg = {
              'userId': store.getters.user_id.toString(),
                'token': store.getters.token.toString(),
                'system': 'datacenter',
                'jg_id': this.task.dwBianma,
                'isWay': '1'
            }
            //全部人员
            await getSzWarningTwoTable(params_sjzx).then(data => {
                if(data.resultdata.length>0){
                    tableData.forEach(item =>{
                        if(item.rygc == '1'){
                            item.zczzSjzx41 =data.resultdata[0].SYGBZZZS
                            item.zcfzSjzx36 =data.resultdata[0].SYGBFZZS
                        }
                    })
                    this.orgId = data.resultdata[0].ORG_ID
                    //this.num1=data.resultdata[0].SYGBZZZS
                    //this.num2=data.resultdata[0].SYGBFZZS
                }
            })
            //机关+参公
            await getSzWarningTwoTable(params_jgcg).then(data => {
                if(data.resultdata.length>0) {
                    tableData.forEach(item =>{
                        if(item.rygc != '1'){
                            item.zczzSjzx41 =data.resultdata[0].SYGBZZZS
                            item.zcfzSjzx36 =data.resultdata[0].SYGBFZZS
                        }
                    })
                    this.orgId = data.resultdata[0].ORG_ID
                    //this.num3 = data.resultdata[0].SYGBZZZS
                    //this.num4 = data.resultdata[0].SYGBFZZS
                }
            })
        },
    }
  }
</script>

<style scoped>
   >>>.el-input.is-disabled .el-input__inner{
    color: #606266;
  }
  /*调整表格文字*/
  >>>.vxe-header--column .vxe-cell--title{
    font-size: 14px;
    font-weight: normal;
    color:#000;
  }
  >>>.vxe-header--row{
    background:#fff;
  }
</style>
